package main

import (
	"github.com/fsnotify/fsnotify"
	"log"
)

func main() {
	water, err := fsnotify.NewWatcher()
	if err != nil {
		log.Fatal("NewWatcher failed: ", err)
	}
	defer water.Close()
	done := make(chan bool)
	go func() {
		defer close(done)
		for {
			select {
			case event, ok := <-water.Events:
				if !ok {
					return
				}
				log.Printf("%s %s\n", event.Name, event.Op)
			case err, ok := <-water.Errors:
				if !ok {
					return
				}
				log.Println("error:", err)

			}
		}
	}()
	err = water.Add("./")
	if err != nil {
		log.Fatal("add failed: ", err)
	}
	<-done
}
